package com.activiti.basic.model;


import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import static javafx.scene.input.KeyCode.N;
import static javafx.scene.input.KeyCode.Y;

/**
 * @author pisory
 * @version 1.0
 * @date 2020/4/5
 */
@Data
public class WebResponse<T> {

    private String code;

    private T body;

    private String message;

    public WebResponse() {

    }
    public static WebResponse buildSuccess(Object body, String message) {
        if (StringUtils.isBlank(message)) {
            message = "操作成功";
        }
        return new WebResponse(Y.getName(), body, message);
    }

    public static WebResponse buildFail(String message) {
        return new WebResponse(N.getName(), null, message);
    }
    public WebResponse(T body) {
        this.body = body;
    }

    public WebResponse(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public WebResponse(String code, T body, String message) {
        this.code = code;
        this.body = body;
        this.message = message;
    }

}
